<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin extends CI_Controller {

    function __construct() { //inisialisasi library dan helper yang perlu di load
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('pagination');
        $this->load->model('simades');
        $log = $this->session->all_userdata();
        if (!isset($log) || $log['login'] != TRUE || $log['privilege'] != 1) {
            redirect('main/logout');
        }
    }

    function index() {
        redirect('admin/home');
    }

    function home() {
        $data['title'] = 'Admin Home';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('template/alert', $data);
        $this->load->view('admin/home', $data);
        $this->load->view('template/foot');
    }

    function kelurahan() {
        $data['title'] = 'Setting Kelurahan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['klrh'] = $this->simades->get_genset()) {
            $data['klrh'] = $this->simades->get_genset();
        } else {
            $data['klrh'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/kelurahan_add', $data);
        $this->load->view('admin/kelurahan', $data);
        $this->load->view('template/foot');
    }

    function kecamatan() {
        $data['title'] = 'Setting Kecamatan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['kec'] = $this->simades->get_genset()) {
            $data['kec'] = $this->simades->get_genset();
        } else {
            $data['kec'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/kec_add', $data);
        $this->load->view('admin/kec', $data);
        $this->load->view('template/foot');
    }

    function kabupaten() {
        $data['title'] = 'Setting Kabupaten';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['kab'] = $this->simades->get_genset()) {
            $data['kab'] = $this->simades->get_genset();
        } else {
            $data['kab'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/kab_add', $data);
        $this->load->view('admin/kab', $data);
        $this->load->view('template/foot');
    }

    function propinsi() {
        $data['title'] = 'Setting Propinsi';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['pro'] = $this->simades->get_genset()) {
            $data['pro'] = $this->simades->get_genset();
        } else {
            $data['pro'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/pro_add', $data);
        $this->load->view('admin/pro', $data);
        $this->load->view('template/foot');
    }

    function agama() {
        $data['title'] = 'Agama';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['agm'] = $this->simades->get_agama()) {
            $data['agm'] = $this->simades->get_agama();
        } else {
            $data['agm'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/agama_add', $data);
        $this->load->view('admin/agama', $data);
        $this->load->view('template/foot');
    }

    function agama_edit() {
        $data['title'] = 'Agama';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        $id = $this->uri->segment(3);
        if ($data['agm'] = $this->simades->get_agama_id($id)) {
            $data['agm'] = $this->simades->get_agama_id($id);
        } else {
            $data['agm'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/agama_edit', $data);
        $this->load->view('template/foot');
    }

    function agama_update() {
        $this->form_validation->set_rules('id', 'ID', 'required');
        $this->form_validation->set_rules('agama', 'Agama', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/agama');
        } else {
            $agama = array(
                'id' => $this->input->post('id'),
                'keterangan' => $this->input->post('agama'),
                'username' => $this->session->userdata('username')
            );
            $this->simades->agama_update($agama);
            redirect('admin/agama');
        }
    }

    function agama_add() {
        $this->form_validation->set_rules('agama', 'Agama', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/agama');
        } else {
            $agama['keterangan'] = $this->input->post('agama');
            $agama['username'] = $this->session->userdata('username');
            $this->simades->agama_add($agama);
            redirect('admin/agama');
        }
    }

    function agama_del() {
        $id = $this->uri->segment(3);
        $this->simades->agama_del($id);
        redirect('admin/agama');
    }

    function sex() {
        $data['title'] = 'Jenis Kelamin';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['sex'] = $this->simades->get_sex()) {
            $data['sex'] = $this->simades->get_sex();
        } else {
            $data['sex'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/sex_add');
        $this->load->view('admin/sex', $data);
        $this->load->view('template/foot');
    }

    function sex_add() {
        $this->form_validation->set_rules('sex', 'Sex', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/sex');
        } else {
            $sex['keterangan'] = $this->input->post('jenis_kelamin');
            $sex['username'] = $this->session->userdata('username');
            $this->simades->sex_add($sex);
            redirect('admin/sex');
        }
    }
    
     function sex_update() {
        $this->form_validation->set_rules('id', 'ID', 'required');
        $this->form_validation->set_rules('Sex', 'sex', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/sex');
        } else {
            $sex = array(
                'id' => $this->input->post('id'),
                'keterangan' => $this->input->post('jenis_kelamin'),
                'username' => $this->session->userdata('username')
            );
            $this->simades->sex_update($sex);
            redirect('admin/sex');
        }
    }
    
    function sex_del() {
        $id = $this->uri->segment(3);
        $this->simades->sex_del($id);
        redirect('admin/sex');
    }
    function pendidikan() {
        $data['title'] = 'Pendidikan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['pend'] = $this->simades->get_pendidikan()) {
            $data['pend'] = $this->simades->get_pendidikan();
        } else {
            $data['pend'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/pendidikan_add', $data);
        $this->load->view('admin/pendidikan', $data);
        $this->load->view('template/foot');
    }

    function pendidikan_add() {
        $this->form_validation->set_rules('pendidikan', 'Pendidikan', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/pendidikan');
        } else {
            $pendidikan['keterangan'] = $this->input->post('pendidikan');
            $pendidikan['username'] = $this->session->userdata('username');
            $this->simades->pendidikan_add($pendidikan);
            redirect('admin/pendidikan');
        }
    }

    function pendidikan_update() {
        $this->form_validation->set_rules('id', 'ID', 'required');
        $this->form_validation->set_rules('pendidikan', 'Pendidikan', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/pendidikan');
        } else {
            $pendidikan = array(
                'id' => $this->input->post('id'),
                'keterangan' => $this->input->post('pendidikan'),
                'username' => $this->session->userdata('username')
            );
            $this->simades->pendidikan_update($pendidikan);
            redirect('admin/pendidikan');
        }
    }

    function pendidikan_edit() {
        $data['title'] = 'Pendidikan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        $id = $this->uri->segment(3);
        if ($data['pend'] = $this->simades->get_pendidikan_id($id)) {
            $data['pend'] = $this->simades->get_pendidikan_id($id);
        } else {
            $data['pend'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('template/alert', $data);
        $this->load->view('admin/pendidikan_edit', $data);
        $this->load->view('template/foot');
    }

    function pendidikan_del() {
        $id = $this->uri->segement(3);
        $this->simades->pendidikan_del($id);
        redirect('admin/pendidikan');
    }

    function pekerjaan() {
        $data['title'] = 'Pekerjaan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        $config['base_url'] = 'http://localhost/simades/index.php/admin/pekerjaan/';
        $config['total_rows'] = $this->simades->get_pek();
        $config['per_page'] = 10;
        $config['num_links'] = 3;
        $config['uri'] = $this->uri->segment(3);
        $this->pagination->initialize($config);
        $data['pkj'] = $this->simades->get_pekerjaan($config);
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/pekerjaan_add', $data);
        $this->load->view('admin/pekerjaan', $data);
        $this->load->view('template/foot');
    }

    function pekerjaan_add() {
        $this->form_validation->set_rules('pekerjaan', 'Pekerjaan', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/pekerjaan');
        } else {
            $pekerjaan['keterangan'] = $this->input->post('pekerjaan');
            $pekerjaan['username'] = $this->session->userdata('username');
            $this->simades->pekerjaan_add($pekerjaan);
            redirect('admin/pekerjaan');
        }
    }

    function pekerjaan_edit() {
        $data['title'] = 'Pekerjaan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        $id = $this->uri->segment(3);
        if ($data['pkj'] = $this->simades->get_pekerjaan_id($id)) {
            $data['pkj'] = $this->simades->get_pekerjaan_id($id);
        } else {
            $data['pkj'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('template/alert', $data);
        $this->load->view('admin/pekerjaan_edit', $data);
        $this->load->view('template/foot');
    }

    function pekerjaan_update() {
        $this->form_validation->set_rules('id', 'ID', 'required');
        $this->form_validation->set_rules('pekerjaan', 'Pekerjaan', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('admin/pekerjaan');
        } else {
            $pekerjaan = array(
                'id' => $this->input->post('id'),
                'keterangan' => $this->input->post('pekerjaan'),
                'username' => $this->session->userdata('username')
            );
            $this->simades->pekerjaan_update($pekerjaan);
            redirect('admin/pekerjaan');
        }
    }

    function pekerjaan_del() {
        $id = $this->uri->segment(3);
        $this->simades->pekerjaan_del($id);
        redirect('admin/pekerjaan');
    }

    function kewarganegaraan() {
        $data['title'] = 'Kewarganegaraan';
        $data['username'] = $this->session->userdata('username');
        if ($data['isi'] = $this->simades->get_sys()) {
            $data['isi'] = $this->simades->get_sys();
        } else {
            $data['isi'] = array();
        }
        if ($data['kewr'] = $this->simades->get_kewarganegaraan()) {
            $data['kewr'] = $this->simades->get_kewarganegaraan();
        } else {
            $data['kewr'] = array();
        }
        $this->load->view('template/head', $data);
        $this->load->view('admin/menu');
        $this->load->view('admin/kwn_add', $data);
        $this->load->view('admin/kewarganegaraan', $data);
        $this->load->view('template/foot');
    }

}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */
?>
